﻿using System;
using System.Linq;
using Core.Model;
using Core.Repository;
using Core.Service;
using Data;

namespace Service
{
    public class UserService : Service<User>, IService<User, Guid>
    {
        public UserService(IRepository<Guid, User> repo)
            : base(repo)
        {
        }
        public UserService() : base(new Repository<User>( new DbContextFactory()))
        {
        }
        public bool IsUnique(string login)
        {
            return Repo.Where(o => o.Login == login).Any();
        }
        public User SigneIn(string login, string password)
        {
            var user = Repo.Where(o => o.Login == login).SingleOrDefault();
            if ((user == null) || (password == user.Password)) return null;
            return user;
        }
        public void ChangePassword(Guid id, string password)
        {
            Repo.Get(id).Password = password;
            Repo.Save();
        }
    }
}
